package com.wc.算法提高课.E第五章_数学知识.概率与数学期望.绿豆蛙的归宿;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/5 23:49
 * @description https://www.acwing.com/activity/content/problem/content/1779/
 */
public class Main {
    /**
     * 背景知识: <p>
     * E(aX + bY) = aE(X) + bE(Y)
     * f[i] = E(i), 表示 i 到达 N的期望距离<p>
     * f[i] += (w[j] + f[j]) / k[i],
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1;
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[M];
    static int[] k = new int[N];
    static double[] f = new double[N];
    static int n, m, idx = 1;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
            add(a, b, c);
            k[a]++;
        }
        out.printf("%.2f\n", dp(1));
        out.flush();
    }

    static double dp(int u) {
        if (f[u] > 0) return f[u];
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            f[u] += (w[i] + dp(j)) / k[u];
        }

        return f[u];
    }

    static void add(int a, int b, int c) {
        e[idx] = b;
        w[idx] = c;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
